import java.io.*;
import java.util.*;

public class java03 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("test1.txt"),"utf-8"));
        String line1,line2,line3;
        br.readLine();
        line1 = br.readLine();
        br.readLine();
        line2 = br.readLine();
        br.readLine();
        line3 = br.readLine();
//        ArrayList<String> list1=new ArrayList<>();
        String[] arr1 = line1.split(";");
        ArrayList<String> list3=new ArrayList<>();
        String[] arr3 = line3.split(";");

        for(int i=0;i<arr3.length;i++){
            String[] str = arr3[i].split(",");
            for(int j=0;j<str.length;j++){
                list3.add(str[j]);
            }
        }
//        ArrayList<String> all = new ArrayList<>();
        HashMap<String,String> time = new HashMap<>();
        for(int i=0;i<arr1.length;i++){
            for(int j=i*4;j<(i+1)*4;j++){
                String[] str = list3.get(j).split(":");//0~15 21
                String[] str1 = str[0].split("~");//0 15
                time.put("0"+arr1[i]+str1[1],str[1]);
            }
        }
//        HashMap<String,String> time = new HashMap<>();


        List<Map.Entry<String,String>> list = new ArrayList<>(time.entrySet());
        list.sort(new Comparator<Map.Entry<String, String>>() {
            @Override
            public int compare(Map.Entry<String, String> o1, Map.Entry<String, String> o2) {
                return Integer.parseInt(o2.getValue())-Integer.parseInt(o1.getValue());
            }
        });
        for(Map.Entry entry:list){
            System.out.print("<"+entry.getKey()+","+entry.getValue()+">  ");
        }
    }
    }
